<!--стилі віконце-вказівник-->

<style>
    #quotePointer{
        position: absolute;
        display: none;
    }
    
    .chat-bubble {
        background-color: wheat;
        border:2px solid #666666;
        font-size:14px;
        line-height:1.3em;
        margin:10px auto;
        padding:10px;
        position:relative;
        text-align:center;
        width:120px;
        -moz-border-radius:10px;
        -webkit-border-radius:10px;
        -moz-box-shadow:0 0 5px #888888;
        -webkit-box-shadow:0 0 5px #888888;
    }
    
    .chat-bubble a {
        color: mediumorchid;
    }

    .chat-bubble-arrow-border {
        border-color: #666666 transparent transparent transparent;
        border-style: solid;
        border-width: 10px;
        height:0;
        width:0;
        position:absolute;
        bottom:-20px;
        left:30px;
    }

    .chat-bubble-arrow {
        border-color: wheat transparent transparent transparent;
        border-style: solid;
        border-width: 10px;
        height:0;
        width:0;
        position:absolute;
        bottom:-19px;
        left:30px;
    }
</style>

<?php $params = array('catId'=>$cat['catId'], 'partnerUrl'=>$partner['url']); ?>    

<script>
    var userIsGuest = Number('<?php echo Yii::app()->user->isGuest; ?>'.replace(/\D+/g,""));
    var page = 'index'; var forumUrl = false; 
</script>

<script src="/js/forumSubscribe.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl; ?>/js/forum.js"></script>
<?php Yii::app()->getClientScript()->registerScriptFile(Yii::app()->baseUrl.'/js/scrollTo.js'); ?>
<?php $this->renderPartial('//partials/partnerMenu', array('partner'=>$partner, 'advertCode'=>$advertCode, 'cat'=>$cat, 'relProfiles'=>$relProfiles, 'userIsWork'=>$userIsWork, 'errorModel'=>$errorModel, 'subCats'=>$subCats, 'curent'=>'forum','show_tabs'=>1));?> 

<script type="text/javascript">
    tinyMCE.init({
        mode : "exact",
        elements : "editor,theme",
        theme : "advanced",
        skin : "default",
        width : 562,
        height : 230,
        invalid_elements: "img, script, h1, h2, h3, h4, h5, h6, h7, font, iframe, object",
        theme_advanced_toolbar_location : false,
        theme_advanced_toolbar_align : false,
        theme_advanced_statusbar_location : false,
        theme_advanced_resizing : false,
        relative_urls : false,
        remove_script_host : true
    });
</script>

<div class="padding4020">
<div class="forum_desclame">Обсуждается все что связанно с партнеркой "<?php echo $partner['name'];?>" и категорией "<?php echo $cat['name'];?>". 
Вы можете задать вопрос сразу предствателю сразу партнерки, или кому еще. Что в голову взбредет короче.</div>
<div class="pull-right showForm">Создать тему</div>
<div class="newThemeForm" style="<?php echo $themeModel->hasErrors() ? 'display:block;' : 'display:none;'; ?>">
<div class="forum_form_cut"></div>
<div class=" comment_form" >
    
    <?php echo CHtml::errorSummary($themeModel, 'Пожалуйста исправьте следующие ошибки:'); ?>
    <?php echo CHtml::beginForm(); ?>
    <div style="width:100%;display: inline-block;"><span class="pull-right close_form"></span></div>
      <?php $userId = !Yii::app()->user->isGuest ? Yii::app()->user->getId() : 'null' ; ?>
    <div class="pull-left">
      <?php echo CHtml::activeLabel($themeModel, 'title',array('style'=>'color:#898989;fomt-size:12px;')); ?>
        <?php echo CHtml::activeTextField($themeModel, 'title', array('class'=>'forum_new_teme', 'style'=>'margin-bottom:15px;')); ?>
        
        <?php echo CHtml::activeLabel($themeModel, 'text',array('style'=>'color:#898989;fomt-size:12px;')); ?>
        <?php echo CHtml::activeTextArea($themeModel, 'text', array('class'=>'text_area_comm', 'id'=>'theme','style'=>'width:550px;')); ?>
    </div>    
        
    <div class="pull-left" style="margin-left: 33px;margin-top: 33px;">
      
         <?php if($partner['delegate1'] + $partner['delegate2'] && $userId != $partner['delegate1'] && $userId != $partner['delegate2']) : ?>
          
                <?php echo CHtml::activeCheckBox($themeModel, 'isSupport',array('id'=>'is_off_comment')); ?> <label for="is_off_comment"><span style="font-size: 12px;line-height: 12px;">Отправить как официальный<br/> вопрос представителю<br/> партнерки.</label>
        <br/>
        <div class="ct_znak"></div>
        <div style="color:#898989;font-size:12px;margin-left: 20px;">Сообщение буддет помечено<br/> вот таким четким значком и <br/>представителю отправится<br/> уведомление.</div>
           
        <?php endif; ?>
      </div>  
                    
  <div class="clearfix"></div> 
  
  <div style="height:40px;"></div>
     <div id="fileUpload" style="width:565px;">
            <?php $this->widget('xupload.XUpload', array(
                'url' => Yii::app()->createUrl("partner/forum/upload"),
                'model' => new XUploadForm, 
                        'attribute' => 'file',
                        'showForm' => false,    
                        'multiple' => true,
                        'options' => array( 
                            'autoUpload' => true, 
                            'maxNumberOfFiles' => 5, 
                            'maxFileSize' => 2000000,
                            'acceptFileTypes' => "js:/(\.|\/)(jpe?g|png|gif)$/i",
                        ),
                        'downloadView' => 'forumDownload',
                        'htmlOptions' => array('id' => 'fileUpload'),
            ));  ?>
        </div>
  
  
    <div class="pull-left">
    <?php echo CHtml::submitButton('Создать',array('class'=>'bt_submit_review')); ?> 
   </div>
   <div class="pull-right"  style="margin-top:10px;">
    
        <?php if(Yii::app()->user->isGuest || (!Yii::app()->user->isGuest && !Yii::app()->user->getState('email')) ) : ?>
            <div class="subscrible_form_com pull-left " style="display: block;">
                <?php echo CHtml::activeTextField($themeModel, 'subscrEmail', array('placeholder'=>'Подписаться на тему', 'class'=>'subscrible_input_com')); ?>
            </div>
        <?php else : ?>
            <?php echo CHtml::activeCheckBox($themeModel, 'subscr',array('id'=>'ts1')); ?><label for="ts1">Подписаться на тему</label>
        <?php endif; ?>
    
   </div>
   <div class="clearfix"></div> 
    
        <?php echo CHtml::activeHiddenField($themeModel, 'partnerId', array('value'=>$partner['partnerid'], 'id'=>'partnerId')); ?>
        <?php echo CHtml::activeHiddenField($themeModel, 'type', array('value'=>'forum')); ?>
        
    <?php echo CHtml::endForm(); ?> 
</div>
</div>
</div>

<?php if(!empty($themes)) : ?>
    <?php foreach ($themes as $item) : ?>
       
 <div>
            <div class="forum_theme">
                <div style="display:none"><?php echo $item['themeId'];?></div>

                <h2><a href="<?php echo Yii::app()->createUrl('partner/forum/theme', CMap::mergeArray($params, array('url'=>$item['url'])));?>"><?php echo $item['title']; ?></a></h2>
                <div class="messageInfo" style="font-size:11px;margin-bottom:20px;">
                    <?php if($item['comDate'] + 86400 > time()) : ?>
                        <span class="is_new_theme"></span>
                    <?php endif; ?>
                    <span class="date">
                        <?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy года в HH:mm", $item['comDate']); ?>
                    </span>&nbsp; 
                    
                    <a class="commentByName" href="#form" data-id="<?php echo $item['themeId'];?>">
                        <span class="login">
                            <?php echo !empty($item['login']) ? !empty($item['displayName']) ? $item['displayName'] : $item['login'] : 'Гость'; ?>
                        </span>
                    </a>&nbsp 
                    <?php if(!empty($item['login'])) : ?>
                        <span class="comment_numb"><?php echo $item['count']; ?></span>  
                    <?php endif; ?>
                    <?php if($item['isSupport']) : ?>
                       &nbsp;&nbsp;<span class="support_q"></span> 
                    <?php endif;?>
                  
                     <?php if($this->isForumModerator) : ?>
                        <div class="pull-right moder_tools">
                            <?php if(!empty($item['role']) && $item['role'] == 'user') : ?>
                                <span class="banUser" style="color: red; cursor: pointer;">
                                    <div style="display: none"><?php echo $item['userid']; ?></div>
                                    Блокировать пользователя
                                </span> |
                            <?php endif; ?>
                            <?php if(empty($item['role']) || $item['role'] == 'user') : ?>
                                <span class="banByIp" title="Бан по IP" style="color: #000; cursor: pointer;"><?php echo $item['userIp']; ?></span> |
                            <?php endif; ?>
                            <a style="color: red;" href="<?php echo Yii::app()->createUrl('partner/forum/editTheme', array('id'=>$item['themeId'])); ?>">Править</a> |
                            <span class="delForumTh" style="color: red; cursor: pointer" data-id="<?php echo $item['themeId']; ?>">Удалить</span>
                        </div>
                    <?php endif; ?>
                </div> 
                
                <div class="messageText">
                  <?php echo $item['text']; ?>
                  <?php if(!empty($item['images'])) : ?>
                    <br/>
                    <?php foreach($item['images'] as $themeImg) : ?>
                        <a style="text-decoration:none;" href="#modal<?php echo $themeImg['imgId']; ?>" class="big-link" data-toggle="modal" >
                            <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/comments/'.$themeImg['smallImg']; ?>" style="width:40px;height:40px;" alt=""/>
                        </a> 
                        <div id="modal<?php echo $themeImg['imgId']; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                <h3 id="myModalLabel">Фото</h3>
                            </div>
                            <div class="modal-body">
                                <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/comments/'.$themeImg['bigImg']; ?>"/>
                            </div>
                        </div>
                     <?php endforeach; ?>
                     <br/> 
                <?php endif; ?>
                </div>
                <br/>
                <span style="float: left; padding-right: 20px"> <a class="addComment bord" href="#form" data-id="<?php echo $item['themeId']; ?>">Ответить</a> </span>
              <a class="qouteMessage bord" href="#form" data-id="<?php echo $item['themeId']; ?>">Цитировать</a>
            </div>

            <div class="forum_post_list">
                <?php if(!empty($item['comments'])) : ?>
     
                    <?php if(3 < $item['countComments']) : ?>
                        <?php $wordEnd = $item['countComments'] < 20 && $item['countComments'] > 10 ? array(0=>'ов', 1=>'ов', 2=>'ов', 3=>'ов', 4=>'ов', 5=>'ов', 6=>'ов', 7=>'ов', 8=>'ов', 9=>'ов') : array(0=>'ов', 1=>'', 2=>'а', 3=>'а', 4=>'а', 5=>'ов', 6=>'ов', 7=>'ов', 8=>'ов', 9=>'ов'); ?>
                        <div class="all_posts" > ↑ <a style="border-bottom: 1px dashed #560029; text-decoration: none; " href="<?php echo Yii::app()->createUrl('partner/forum/theme', CMap::mergeArray($params, array('url'=>$item['url'])));?>">&nbsp;Показать <?php echo $item['countComments']; ?> ответ<?php echo $wordEnd[$item['countComments']%10];?></a></div>
                    <?php endif; ?>
               
                    <?php foreach($item['comments'] as $com) : ?>
                        <div class="forum_post">
                          <span id="<?php echo $com['comId']; ?>" style="position:absolute; top:-100px">&nbsp;</span>
                          <div class="post_header">
                            <div style="display:none"><?php echo $item['themeId'];?></div>
                            <div class="themeUrl" style="display:none"><?php echo Yii::app()->createAbsoluteUrl('partner/forum/theme', CMap::mergeArray($params, array('url'=>$item['url'])));?></div>
                            <a href="<?php echo '#'.$com['comId']; ?>" style="text-decoration:none;" class="comCounter"><?php echo '#'.$com['comId']; ?></a>
                            <span  class="date_forum_post"><?php echo Yii::app()->dateFormatter->format("dd MMMM yyyy года в HH:mm", $com['comDate']); ?></span>&nbsp;
                            <?php if(!empty($com['user'])) : ?>
                                <a class="commentByName" href="#form" data-id="<?php echo $item['themeId'];?>">
                                    <span class="login">
                                        <?php echo !empty($com['user']['displayName']) ? $com['user']['displayName'] : $com['user']['login']; ?>
                                    </span>
                                </a>&nbsp; 
                                <span class="comment_numb">
                                    <?php echo $com['user']['reviews'] + $com['user']['newsComments'] + $com['user']['forumComments'] + $com['user']['revComments'] + $com['user']['blogComments']; ?>
                                </span>
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                <a class="commentByName" href="#form" data-id="<?php echo $item['themeId'];?>">
                                    <span class="login" style="display: none">
                                        <?php echo !empty($com['user']['displayName']) ? $com['user']['displayName'] : $com['user']['login']; ?>
                                    </span>
                                    Обратиться по нику
                                </a>
                            <?php else : ?>
                                <a class="commentGuestOnMain" href="#form" data-id="<?php echo $item['themeId'];?>">
                                    <span class="login">
                                        Гость
                                    </span>
                                </a>&nbsp;
                            <?php endif; ?>
                            
                            <?php if($this->isForumModerator || $this->moderPost) : ?>
                                <span style="float: right">
                                    <div style="display: none;"> <?php echo $com['comId']; ?> </div> 
                                    <?php if($this->isForumModerator) : ?>
                                        <?php if(!empty($com['user']) && $com['user']['role'] == 'user') : ?>
                                            <span class="banUser" style="color: red; cursor: pointer;">
                                                <div style="display: none"><?php echo $com['user']['userid']; ?></div>
                                                Блокировать пользователя
                                            </span> |
                                        <?php endif; ?>
                                        <?php if(empty($com['user']) || $com['user']['role'] == 'user') : ?>
                                            <span class="banByIp" title="Бан по IP" style="color: red; cursor: pointer;"><?php echo $com['userIp']; ?></span> |
                                        <?php endif; ?>
                                    <?php endif; ?>       
                                    <a style="color: red;" href="<?php echo Yii::app()->createUrl('partner/forum/editComment', array('id'=>$com['comId'])); ?>">Править</a> |
                                    <span class="delForumCom" style="color: red; cursor: pointer">Удалить</span>
                                </span>
                            <?php endif; ?>

                            <?php if(!empty($com['user']) && ($partner['delegate1'] == $com['user']['userid'] || $partner['delegate2'] == $com['user']['userid']) ) : ?>
                                &nbsp;&nbsp;<span class="support_q"></span> 
                            <?php endif; ?>
                                
                            </div>    
                                
                            <div class="post_message">
                                <!-- чтобы не удлиннять ленту не показываю цитаты. Если в сообщении только цитаты - будет пустое сообщение -->
                                <script LANGUAGE="JavaScript">
                                    document.write('<?php echo CPartnerkiHelper::jsString(preg_replace('/\[quote([\s\S]*)\[\/quote\]/', '', $com['text'])); ?>');
                                </script>
                            </div>
                              <?php if(!empty($com['images'])) : ?>
                                    <br/><br/>
                                  <?php foreach($com['images'] as $comImg) : ?>
                                    <a style="text-decoration:none;" href="#com-modal<?php echo $comImg['imgId']; ?>" class="big-link" data-toggle="modal" >
                                        <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/comments/'.$comImg['smallImg']; ?>" alt=""/>
                                    </a> 
                                    <div id="com-modal<?php echo $comImg['imgId']; ?>" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
                                        <div class="modal-header">
                                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
                                            <h3 id="myModalLabel">Фото</h3>
                                        </div>
                                        <div class="modal-body">
                                            <img src="<?php echo Yii::app()->baseUrl.'/images/uploads/comments/'.$comImg['bigImg']; ?>"/>
                                        </div>
                                    </div>
                                  <?php endforeach; ?>
                              <?php endif; ?>
                          <br/>
                        </div>
                    <?php endforeach; ?>
                   
                <?php endif; ?>
               
         <div class="clearfix"></div>
         <div class="padding4020">
         <div class="pull-left">
             <a class="addComment addpst" href="#form" data-id="<?php echo $item['themeId'];?>">Ответить</a>
          </div>   
                        
             <div class="pull-right">         
                  <?php if(Yii::app()->user->isGuest) : ?>
                    <div class="subscrible_form_com pull-left " style="display: block;"> 
                        <span class="type" style="display: none">forum_topic</span>
                        <span class="typeId" style="display: none"><?php echo $item['themeId']; ?></span>
                        <input placeholder="Подписаться на комментарии" class="subscrible_input_com" type="text" value="" name=""/>    
                        <div class="subscrible_sub" id="submitSubscrWindow"> </div>
                    </div>
                  <?php else : ?>
                   <?php 
                   $isSign = false;
                   if(!empty($isUserSign)) : 
                       foreach ($isUserSign as $uSign) {
                            if($item['themeId'] == $uSign['typeId']) {
                                $isSign = true; break;
                            }
                       }
                   endif;?>
                       <span>
                            <div class="subscrible_post" style="margin-top: -3px; margin-right: 7px"></div>
                            <span class="type" style="display: none">forum_topic</span>
                            <span class="userId" style="display: none"><?php echo Yii::app()->user->getId(); ?></span>
                            <span class="typeId" style="display: none"><?php echo $item['themeId']; ?></span>
                            <?php echo CHtml::hiddenField('', Yii::app()->user->getState('email'), array('class'=>'subscrible_input_com')); ?>
                            <div style="font-size:13px; color:#882d4f; cursor: pointer" class="<?php echo $isSign ? 'unsubscr' : 'subscr' ?> pull-left" href="javascript:void(0);" data-type="forum" data-typeId="<?php echo $partner['partnerid']; ?>" data-userId="<?php echo Yii::app()->user->getId(); ?>" >
                                <?php echo $isSign ? 'Отписаться от комментариев' : 'Подписаться на комментарии'; ?> 
                            </div>
                       </span>    
                 <?php endif; ?>       
             </div>
        </div>                
            </div> 
       </div>    







    <?php endforeach; ?>


   
    <?php echo CHtml::errorSummary($commentModel); ?>
    <div class="pages"> <?php $this->widget('CLinkPager', array('pages' => $pagination)); ?> </div>
    
    
   
    <div  id="commentFileUpload" style="display: none;">
        <div class="padding040">
         <div class="forum_form_cut"></div>
<div class=" comment_form" >
        <?php echo CHtml::beginForm('', 'post', array('id'=>'form')); ?>
        <div style="width:100%;display: inline-block;"><span class="pull-right close_form"></span></div>
            <?php echo CHtml::activeTextArea($commentModel, 'text', array('id'=>'editor','class'=>'text_area_comm','style'=>'width:600px;')); ?>
            
            <div id="commentFileUpload">
                <?php $this->widget('xupload.XUpload', array(
                    'url' => Yii::app()->createUrl("partner/forum/upload"),
                    'model' => new XUploadForm, 
                    'attribute' => 'file',
                    'showForm' => false,    
                    'multiple' => true,
                    'options' => array( 
                        'autoUpload' => true, 
                        'maxNumberOfFiles' => 5, 
                        'maxFileSize' => 500000,
                        'acceptFileTypes' => "js:/(\.|\/)(jpg|png|gif)$/i",
                    ),
                    'downloadView'=>'downloadViewOrigin',
                    'htmlOptions' => array('id'=>'commentFileUpload'),
                ));  ?>
            </div>
            
            <?php echo CHtml::activeHiddenField($commentModel, 'themeId', array('value'=>'', 'id'=>'themeId')); ?>

            <?php echo CHtml::submitButton('Ответить', array('class'=>'bt_submit_review')); ?>
        <?php echo CHtml::endForm(); ?>
    </div>
     </div>
      </div>
    
<?php else : ?>    
    Сейчас нет тем. Можно создать новую.
<?php endif; ?> 
    
 
    
<div id="quotePointer">
    <div class="chat-bubble" >
        <a href="#form" class="quoteText">Цитировать</a>
        <div class="chat-bubble-arrow-border"></div>
        <div class="chat-bubble-arrow"></div>
    </div>
</div>    
    
<div class="modal hide fade" id="myModal">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
    <h3>Уведомление</h3>
  </div>
  <div class="modal-body">
    
  </div>
  <div class="modal-footer">
      <button type="button" class="close" data-dismiss="modal" aria-hidden="true"><a href="#" class="btn">Закрыть</a></button>
  </div>
</div>
